package com.ftg.product.exam.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.product.exam.entity.SysEmpRole;
import com.ftg.product.exam.service.SysEmpRoleService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.diboot.core.vo.*;
import com.ftg.product.exam.entity.SysEmployee;
import com.ftg.product.exam.dto.SysEmployeeDTO;
import com.ftg.product.exam.vo.SysEmployeeListVO;
import com.ftg.product.exam.vo.SysEmployeeDetailVO;
import com.ftg.product.exam.service.SysEmployeeService;

import lombok.extern.slf4j.Slf4j;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
* 1.3 员工信息(名称、性别、所在部门、职务、邮箱、手机号、岗位) 相关Controller
* @author kangjx
* @version 1.0
* @date 2021-01-15
* Copyright © ftg
*/
@Api(tags = {"1.3 员工信息(名称、性别、所在部门、职务、邮箱、手机号、岗位)"})
@RestController
@RequestMapping("/sysEmployee")
@Slf4j
public class SysEmployeeController extends BaseCustomCrudRestController<SysEmployee> {
    @Autowired
    private SysEmployeeService sysEmployeeService;

    @Autowired
    private SysEmpRoleService sysEmpRoleService;


    @ApiOperation(value = "员工登录")
    @PostMapping("/employeelogin/{empphone}&{emppassword}")
    public List<Map<String,Object>> login(@ApiParam("手机号") @PathVariable String empphone, @ApiParam("登陆密码") @PathVariable String emppassword){
        return sysEmployeeService.login(empphone,emppassword);

    }

    @ApiOperation("查询全部员工信息,不包括密码")
    @PostMapping("/query")
    public List<Map<String,Object>> query(@RequestParam(value="empname",required = false) String empname, Long emporgcode, Long empjobcode, Long emppostcode){
        return sysEmployeeService.query(empname, emporgcode,empjobcode, emppostcode);
    }

    /***
    * 查询ViewObject的分页数据
    * <p>
    * url请求参数示例: /list?field=abc&pageIndex=1&orderBy=abc:DESC
    * </p>
    * @return
    * @throws Exception
    */
    @ApiOperation(value = "获取列表分页数据")
    @GetMapping("/list")
    public JsonResult getViewObjectListMapping(SysEmployeeDTO queryDto, Pagination pagination) throws Exception{
        return super.getViewObjectList(queryDto, pagination, SysEmployeeListVO.class);
    }

    /***
    * 根据资源id查询ViewObject
    * @param id ID
    * @return
    * @throws Exception
    */
    @ApiOperation(value = "根据ID获取详情数据")
    @GetMapping("/{id}")
    public JsonResult getViewObjectMapping(@PathVariable("id")Long id) throws Exception{
        return super.getViewObject(id, SysEmployeeDetailVO.class);
    }

    /***
    * 创建资源对象
    * @param entity
    * @return JsonResult
    * @throws Exception
    */
    @ApiOperation(value = "新建数据")
    @PostMapping("/")
    public JsonResult createEntityMapping(@Valid @RequestBody SysEmployee entity) throws Exception {
        Long maxid = sysEmpRoleService.selectmaxid() + 1;
        sysEmpRoleService.saverole(maxid);
        return super.createEntity(entity);
    }

    /***
    * 根据ID更新资源对象
    * @param entity
    * @return JsonResult
    * @throws Exception
    */
    @ApiOperation(value = "根据ID更新数据")
    @PutMapping("/{id}")
    public JsonResult updateEntityMapping(@PathVariable("id")Long id, @Valid @RequestBody SysEmployee entity) throws Exception {
        return super.updateEntity(id, entity);
    }

    /***
    * 根据id删除资源对象
    * @param id
    * @return
    * @throws Exception
    */
    @ApiOperation(value = "根据ID删除数据")
    @DeleteMapping("/{id}")
    public JsonResult deleteEntityMapping(@PathVariable("id")Long id) throws Exception {
        return super.deleteEntity(id);
    }

    @DeleteMapping("/deletes/{ids}")
    @ApiOperation(value = "根据多条ID删除多条数据")
    public int deletes(@ApiParam("多条ID") @PathVariable List<Long> ids){
        return sysEmployeeService.deletes(ids);
    }

} 